
package com.idealighter.game.games.zjh.handler;

import com.google.common.collect.Sets;

import com.idealighter.game.core.annotation.ResMsgHandler;
import com.idealighter.game.games.zjh.ZjhPlayer;
import com.idealighter.game.games.zjh.message.ResRobotSeeCardMsg;
import com.idealighter.game.message.ModuleMsgIdConstant;
import com.idealighter.game.message.core.ResMessage;
import com.idealighter.game.robot.core.Player;
import com.idealighter.game.robot.handler.ResMessageHandler;

import java.util.Set;

@ResMsgHandler(ModuleMsgIdConstant.Zjh.RES_ROBOT_SEE_CARD)

public class ResRobotSeeCardHandler implements ResMessageHandler {

  // private static final Logger LOG = LoggerFactory.getLogger(ResRobotSeeCardHandler.class);
  // A K Q的牌id
  private static final Set<Integer> AKQ_CARD_IDS =
      Sets.newHashSet(0, 11, 12, 13, 24, 25, 26, 27, 28, 39, 40, 41);

  @Override
  public void action(Player player, ResMessage message) {
    ResRobotSeeCardMsg msg = (ResRobotSeeCardMsg) message;
    ZjhPlayer zjhPlayer = (ZjhPlayer) player;
    int cardsType = msg.getCardsType();
    zjhPlayer.cardsType = cardsType;
    zjhPlayer.sawCard = true;
    zjhPlayer.win = msg.getWin() != 0;

    boolean hasAkq = false;
    for (Integer cardId : msg.getCards()) {
      if (AKQ_CARD_IDS.contains(cardId)) {
        hasAkq = true;
        break;
      }
    }

    zjhPlayer.hasAkq = hasAkq;
    zjhPlayer.bet();
  }
}
